-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Allow visit Sprite without camera for render to texture #17824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
A fix to allow render to texture like this ''' Director::getInstance()->setProjection(Director::Projection::_2D); m_renderTarget->beginWithClear(1, 0, 0, 0.2, m_depthClear, 0); m_sprite->visit(Director::getInstance()->getRenderer(), Mat4::IDENTITY, 0); m_renderTarget->end(); Director::getInstance()->setProjection(Director::Projection::_3D); '''
cocos/2d/CCSprite.cpp
Outdated
@@ -1054,7 +1054,10 @@ void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) | |||
// Don't calculate the culling if the transform was not updated | |||
auto visitingCamera = Camera::getVisitingCamera(); | |||
auto defaultCamera = Camera::getDefaultCamera(); | |||
if (visitingCamera == defaultCamera) { | |||
if (visitingCamera == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NULL -> nullptr
Interesting, why you set |
I started using the USER cameras and then I saw that I didn't need the default camera. Also, I think that when rendering to texture, the sprite was showing on the default camera on screen. Maybe I could add an extra USER camera for rendering to texture but this was more straightforward to me. Furthermore, I'm not sure about this, but I see that some objects do some computation if there is a default camera on the "visit" or "render" functions when enter this Thanks! |
Oh, you mean why I use this line? |
* commit '639737286f594f3e06c07b22b352dddb01858883': before draw event (cocos2d#17669) Handle auto layout with scaled widget (cocos2d#17822) fix to problem with updating APK in Google Play keeping old OBB (cocos2d#17689) update console to fix compiling issue on with Xcode 8.3+ (cocos2d#17862) Fix iskindof (cocos2d#17785) [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (cocos2d#17857) fix action running times for instant actions (cocos2d#17849) make fps stable on iOS (cocos2d#17852) [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (cocos2d#17848) LayerRadialGradient works on mac and iOS (cocos2d#17826) Fixing serious XMLHTTP leak when CC_ENABLE_GC_FOR_NATIVE_OBJECTS enabled (cocos2d#17844) Call 'update' method in 'stop/stopAll' to cleanup immediately (cocos2d#17846) Add const keyword to Node::isScheduled (cocos2d#17841) small BillBoard optimizations (cocos2d#17825) Allow visit Sprite without camera for render to texture (cocos2d#17824) # Conflicts: # cocos/base/CCDirector.cpp # cocos/base/CCDirector.h # cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp # cocos/ui/UILayoutManager.cpp # tools/cocos2d-console
A fix to allow render to texture like this
otherwise, crashes
PS: I have disabled the default camera in my Scene with